<?php echo \think\facade\View::fetch("public/header"); ?>

    <div id="right">
        <div id="content">
            <div id="breadcrumb">
                <a href="/admin/index/index">首页</a> &gt;
                <a href="/admin/comment/index/">评论管理</a> &gt;
                评论列表
            </div>

            <div id="choose_div">
                <span>筛选：</span>
                <select id="status">
                    <option value="1" <?php if ($status ==1) echo 'selected="selected"'; ?> >正常</option>
                    <option value="2" <?php if ($status ==2) echo 'selected="selected"'; ?> >回收站</option>
                </select>
                <button id="search" class="btn">搜索</button>
<!--                <a id="multi_delete" href="javascript:void(0);">删除选中任务</a>-->

                <!--                <a class="add" href="/admin/category/add/">增加分类</a>-->
            </div>

            <table class="list">
                <tbody>
                <tr>
                    <th></th>
                    <th>ID</th>
                    <th>文章id</th>
                    <th>评论内容</th>
<!--                    <th>邮箱</th>-->
                    <th>昵称</th>
                    <th>发布时间</th>
                    <th>操作</th>
                </tr>
                <?php foreach ($commentList as $item): ?>
                    <tr>
                        <td><input type="checkbox" class="task-checkbox" name="TaskId[]" value=""></td>
                        <td><?php echo $item['comment_id']; ?></td>
                        <td><?php echo $item['article_id']; ?></td>
                        <td><?php echo $item['comment_content']; ?></td>
<!--                        <td>--><?php //echo $item['email']; ?><!--</td>-->
                        <td><?php echo $item['nickname']; ?></td>
                        <td><?php echo date("Y-m-d H:i:s", $item['add_time']); ?></td>
                        <td>
                            <?php if ($item['status'] == 1): ?>
                                <a class="update_ing"
                                   href="/admin/comment/garbage/comment_id/<?php echo $item['comment_id']; ?>/" data-id="<?php echo $item['comment_id']; ?>">移入回收站</a>
                            <?php elseif ($item['status'] == 2): ?>
                                <a class="update_ing"
                                   href="/admin/comment/resume/comment_id/<?php echo $item['comment_id']; ?>/" data-id="<?php echo $item['comment_id']; ?>">恢复</a>
                                <a class="update_ing"
                                   href="/admin/comment/delete/comment_id/<?php echo $item['comment_id']; ?>/" data-id="<?php echo $item['comment_id']; ?>">彻底删除</a>
                            <?php endif; ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>

<?php echo \think\facade\View::fetch("public/footer"); ?>
<script>
    $("#search").click(function () {
        let status = $("#status").val();
        console.log(status);
        // windows doucment
        // console.log(location.href);
        let url = "/admin/comment/index/status/"+status+"/";
        console.log(url);
        location.href = url;
    });

    $(".update_ing").click(function () {
        console.log(111);
        let href = $(this).attr('href');
        console.log(href);

        let _this = this;

        let id = $(this).data('id');

        $.ajax({
            url: href,
            type: "post",
            data: {comment_id: id},
            success: function (result) {
                console.log(result);
                if (result.status == 0) {
                    alert("操作成功");
                    $(_this).parent().parent().remove();
                    // location.reload();
                } else {
                    alert(result.message);
                }
            }
        });
        return false;
    });

</script>

